<template>
  <div class="header-container">
    <!-- 折叠按钮 -->
    <div class="collapse-btn" @click="toggleCollapse">
      <i :class="collapseIcon"></i>
    </div>
    
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item 
          v-for="item in breadcrumbList" 
          :key="item.path"
        >
          {{ item.meta.title }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    
    <!-- 右侧功能区 -->
    <div class="header-right">
      <!-- 全屏按钮 -->
      <div class="fullscreen-btn" @click="toggleFullscreen">
        <el-tooltip :content="isFullscreen ? '退出全屏' : '全屏'">
          <i :class="fullscreenIcon"></i>
        </el-tooltip>
      </div>
      
      <!-- 用户信息 -->
      <el-dropdown @command="handleCommand">
        <span class="user-info">
          <img :src="userAvatar" class="user-avatar">
          <span>{{ userName }}</span>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="profile">个人中心</el-dropdown-item>
          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      isFullscreen: false,
      breadcrumbList: [],
      userName: '',
      userAvatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif'
    }
  },
  computed: {
    collapseIcon() {
      return this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
    },
    fullscreenIcon() {
      return this.isFullscreen ? 'el-icon-close-notification' : 'el-icon-rank'
    }
  },
  watch: {
    $route() {
      this.getBreadcrumb()
    }
  },
  created() {
    this.getBreadcrumb()
  },
  methods: {
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
      this.$emit('collapse-change', this.isCollapse)
    },
    toggleFullscreen() {
      if (!document.fullscreenElement) {
        document.documentElement.requestFullscreen()
        this.isFullscreen = true
      } else {
        if (document.exitFullscreen) {
          document.exitFullscreen()
          this.isFullscreen = false
        }
      }
    },
    getBreadcrumb() {
      this.breadcrumbList = this.$route.matched.filter(item => item.meta && item.meta.title)
    },
    handleCommand(command) {
      if (command === 'logout') {
        this.$confirm('确定退出系统吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(() => {
          // 这里添加退出登录逻辑
          this.$message.success('退出成功')
          this.$router.push('/login')
        })
      } else if (command === 'profile') {
        this.$router.push('/profile')
      }
    }
  }
}
</script>

<style scoped>
.header-container {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.collapse-btn {
  font-size: 20px;
  cursor: pointer;
  margin-right: 20px;
}

.breadcrumb {
  margin-left: 20px;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.fullscreen-btn {
  font-size: 20px;
  cursor: pointer;
  margin-right: 20px;
}

.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 8px;
}
</style>